package ltd.dujiabao.capability.domain.capmng.sync.feature;

import java.util.Collections;
import java.util.HashMap;
import java.util.Map;

import org.springframework.stereotype.Component;

import ltd.dujiabao.capability.domain.capmng.sync.Transferor;

/**
 * @author : DuJiabao
 * @Project : ddd-capability
 * @Time : 2024/4/8 21:57
 * @Desc :
 */
@Component
public class FeatureTransferor implements Transferor {
    private static final Map<Long, String> MASK_MAP = new HashMap<>();

    static {
        MASK_MAP.put(0x01L, "x");
        MASK_MAP.put(0x02L, "xx");
        MASK_MAP.put(0x04L, "xxx");
        MASK_MAP.put(0x08L, "xxxx");
        MASK_MAP.put(0x10L, "new_module_spec");
    }

    @Override
    public Map<String, Object> transfer(Object original) {
        Map<String, Boolean> body = new HashMap<>();
        long features = (Long) original;
        for (Map.Entry<Long, String> entry : MASK_MAP.entrySet()) {
            if ((entry.getKey() & features) > 0) {
                body.put(entry.getValue(), true);
            }
        }
        return Collections.singletonMap("features", body);
    }
}
